﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace ParticlePlayground
{
	// Token: 0x02000167 RID: 359
	[Serializable]
	public class ManipulatorObjectC
	{
		// Token: 0x14000013 RID: 19
		// (add) Token: 0x06000868 RID: 2152 RVA: 0x00031F88 File Offset: 0x00030188
		// (remove) Token: 0x06000869 RID: 2153 RVA: 0x00031FA4 File Offset: 0x000301A4
		public event OnPlaygroundParticle particleEventEnter;

		// Token: 0x14000014 RID: 20
		// (add) Token: 0x0600086A RID: 2154 RVA: 0x00031FC0 File Offset: 0x000301C0
		// (remove) Token: 0x0600086B RID: 2155 RVA: 0x00031FDC File Offset: 0x000301DC
		public event OnPlaygroundParticle particleEventExit;

		// Token: 0x14000015 RID: 21
		// (add) Token: 0x0600086C RID: 2156 RVA: 0x00031FF8 File Offset: 0x000301F8
		// (remove) Token: 0x0600086D RID: 2157 RVA: 0x00032014 File Offset: 0x00030214
		public event OnPlaygroundParticle particleEventBirth;

		// Token: 0x14000016 RID: 22
		// (add) Token: 0x0600086E RID: 2158 RVA: 0x00032030 File Offset: 0x00030230
		// (remove) Token: 0x0600086F RID: 2159 RVA: 0x0003204C File Offset: 0x0003024C
		public event OnPlaygroundParticle particleEventDeath;

		// Token: 0x14000017 RID: 23
		// (add) Token: 0x06000870 RID: 2160 RVA: 0x00032068 File Offset: 0x00030268
		// (remove) Token: 0x06000871 RID: 2161 RVA: 0x00032084 File Offset: 0x00030284
		public event OnPlaygroundParticle particleEventCollision;

		// Token: 0x06000872 RID: 2162 RVA: 0x000320A0 File Offset: 0x000302A0
		public virtual bool Contains(Vector3 position, Vector3 mPosition)
		{
			if (this.shape == MANIPULATORSHAPEC.Infinite)
			{
				return true;
			}
			if (this.shape == MANIPULATORSHAPEC.Box)
			{
				if (!this.inverseBounds)
				{
					return this.bounds.Contains(this.transform.inverseRotation * (position - mPosition));
				}
				return !this.bounds.Contains(this.transform.inverseRotation * (position - mPosition));
			}
			else
			{
				if (!this.inverseBounds)
				{
					return Vector3.Distance(position, mPosition) <= this.size;
				}
				return Vector3.Distance(position, mPosition) >= this.size;
			}
		}

		// Token: 0x06000873 RID: 2163 RVA: 0x0003214C File Offset: 0x0003034C
		public virtual void SendParticleEventEnter()
		{
			if (this.initializedEventEnter)
			{
				this.particleEventEnter(this.manipulatorEventParticle);
			}
		}

		// Token: 0x06000874 RID: 2164 RVA: 0x0003216C File Offset: 0x0003036C
		public virtual void SendParticleEventExit()
		{
			if (this.initializedEventExit)
			{
				this.particleEventExit(this.manipulatorEventParticle);
			}
		}

		// Token: 0x06000875 RID: 2165 RVA: 0x0003218C File Offset: 0x0003038C
		public virtual void SendParticleEventBirth()
		{
			if (this.initializedEventBirth)
			{
				this.particleEventBirth(this.manipulatorEventParticle);
			}
		}

		// Token: 0x06000876 RID: 2166 RVA: 0x000321AC File Offset: 0x000303AC
		public virtual void SendParticleEventDeath()
		{
			if (this.initializedEventDeath)
			{
				this.particleEventDeath(this.manipulatorEventParticle);
			}
		}

		// Token: 0x06000877 RID: 2167 RVA: 0x000321CC File Offset: 0x000303CC
		public virtual void SendParticleEventCollision()
		{
			if (this.initializedEventCollision)
			{
				this.particleEventCollision(this.manipulatorEventParticle);
			}
		}

		// Token: 0x06000878 RID: 2168 RVA: 0x000321EC File Offset: 0x000303EC
		public virtual PlaygroundEventParticle GetParticle(int index)
		{
			if (this.particles == null || this.particles.Count == 0 || index > this.particles.Count)
			{
				return null;
			}
			return this.GetParticle(this.particles[index].particleSystemId, this.particles[index].particleId);
		}

		// Token: 0x06000879 RID: 2169 RVA: 0x00032250 File Offset: 0x00030450
		public virtual PlaygroundEventParticle GetParticle(int particleSystemId, int particleId)
		{
			PlaygroundEventParticle playgroundEventParticle = new PlaygroundEventParticle();
			if (PlaygroundC.reference.particleSystems[particleSystemId].UpdateEventParticle(playgroundEventParticle, particleId))
			{
				return playgroundEventParticle;
			}
			return null;
		}

		// Token: 0x0600087A RID: 2170 RVA: 0x00032284 File Offset: 0x00030484
		public virtual List<PlaygroundEventParticle> GetParticles()
		{
			List<PlaygroundEventParticle> list = new List<PlaygroundEventParticle>();
			for (int i = 0; i < this.particles.Count; i++)
			{
				if (PlaygroundC.reference.particleSystems[this.particles[i].particleSystemId].UpdateEventParticle(this.manipulatorEventParticle, this.particles[i].particleId))
				{
					list.Add(this.manipulatorEventParticle.Clone());
				}
			}
			return list;
		}

		// Token: 0x0600087B RID: 2171 RVA: 0x00032308 File Offset: 0x00030508
		public virtual bool ContainsParticle(int particleSystemId, int particleId)
		{
			for (int i = 0; i < this.particles.Count; i++)
			{
				if (this.particles[i % this.particles.Count].particleSystemId == particleSystemId && this.particles[i % this.particles.Count].particleId == particleId)
				{
					return true;
				}
			}
			return false;
		}

		// Token: 0x0600087C RID: 2172 RVA: 0x0003237C File Offset: 0x0003057C
		public virtual bool IsSameId(int compareId)
		{
			return this.manipulatorId == compareId;
		}

		// Token: 0x0600087D RID: 2173 RVA: 0x00032390 File Offset: 0x00030590
		public virtual bool AddParticle(int particleSystemId, int particleId)
		{
			if (this.particles == null)
			{
				return false;
			}
			for (int i = 0; i < this.particles.Count; i++)
			{
				if (this.particles == null || this.particles[i] == null)
				{
					return false;
				}
				if (this.particles[i % this.particles.Count].particleSystemId == particleSystemId && this.particles[i % this.particles.Count].particleId == particleId)
				{
					return false;
				}
			}
			this.particles.Add(new ManipulatorParticle(particleSystemId, particleId));
			return true;
		}

		// Token: 0x0600087E RID: 2174 RVA: 0x00032440 File Offset: 0x00030640
		public virtual bool RemoveParticle(int particleSystemId, int particleId)
		{
			if (this.particles == null)
			{
				return false;
			}
			bool result = false;
			for (int i = 0; i < this.particles.Count; i++)
			{
				if (this.particles == null || this.particles[i] == null)
				{
					return false;
				}
				if (this.particles[i % this.particles.Count].particleSystemId == particleSystemId && this.particles[i % this.particles.Count].particleId == particleId)
				{
					this.particles.RemoveAt(i % this.particles.Count);
					result = true;
				}
			}
			return result;
		}

		// Token: 0x0600087F RID: 2175 RVA: 0x000324F8 File Offset: 0x000306F8
		public virtual void KillAllParticles()
		{
			if (this.particles == null)
			{
				return;
			}
			for (int i = 0; i < this.particles.Count; i++)
			{
				if (i >= this.particles.Count || i < 0)
				{
					return;
				}
				PlaygroundC.reference.particleSystems[this.particles[i].particleSystemId].Kill(this.particles[i].particleId);
				this.particles.RemoveAt(i);
				if (i > 0)
				{
					i--;
				}
			}
		}

		// Token: 0x06000880 RID: 2176 RVA: 0x00032594 File Offset: 0x00030794
		public virtual bool ContainsNonAffectedParticle(int particleSystemId, int particleId)
		{
			for (int i = 0; i < this.nonAffectedParticles.Count; i++)
			{
				if (this.nonAffectedParticles[i].particleSystemId == particleSystemId && this.nonAffectedParticles[i].particleId == particleId)
				{
					return true;
				}
			}
			return false;
		}

		// Token: 0x06000881 RID: 2177 RVA: 0x000325F0 File Offset: 0x000307F0
		public virtual void AddNonAffectedParticle(int particleSystemId, int particleId)
		{
			this.nonAffectedParticles.Add(new ManipulatorParticle(particleSystemId, particleId));
		}

		// Token: 0x06000882 RID: 2178 RVA: 0x00032604 File Offset: 0x00030804
		public virtual bool RemoveNonAffectedParticle(int particleSystemId, int particleId)
		{
			for (int i = 0; i < this.nonAffectedParticles.Count; i++)
			{
				if (this.nonAffectedParticles[i].particleSystemId == particleSystemId && this.nonAffectedParticles[i].particleId == particleId)
				{
					this.nonAffectedParticles.RemoveAt(i);
					return true;
				}
			}
			return false;
		}

		// Token: 0x06000883 RID: 2179 RVA: 0x0003266C File Offset: 0x0003086C
		public virtual bool LifetimeFilter(float life, float total)
		{
			if (!this.applyLifetimeFilter)
			{
				return true;
			}
			float num = life / total;
			return num >= this.lifetimeFilterMinimum && num <= this.lifetimeFilterMaximum;
		}

		// Token: 0x06000884 RID: 2180 RVA: 0x000326A8 File Offset: 0x000308A8
		public virtual bool ParticleFilter(int p, int total)
		{
			if (!this.applyParticleFilter)
			{
				return true;
			}
			float num = (float)p * 1f / ((float)total * 1f);
			return num >= this.particleFilterMinimum && num <= this.particleFilterMaximum;
		}

		// Token: 0x06000885 RID: 2181 RVA: 0x000326F0 File Offset: 0x000308F0
		public virtual void Update()
		{
			if (this.enabled && this.transform.Update())
			{
				this.manipulatorId = this.transform.instanceID;
				if (this.trackParticles)
				{
					this.initializedEventEnter = (this.particleEventEnter != null);
					this.initializedEventExit = (this.particleEventExit != null);
					this.initializedEventBirth = (this.particleEventBirth != null);
					this.initializedEventDeath = (this.particleEventDeath != null);
					this.initializedEventCollision = (this.particleEventCollision != null);
				}
				else if (this.particles.Count > 0)
				{
					this.particles.Clear();
				}
				if (this.type == MANIPULATORTYPEC.Property || this.type == MANIPULATORTYPEC.Combined)
				{
					this.property.Update();
					this.property.SetLocalVelocity(this.transform.rotation, this.property.velocity);
					if (this.property.type == MANIPULATORPROPERTYTYPEC.Math)
					{
						this.property.UpdateMathProperty(this.transform.position);
					}
					for (int i = 0; i < this.properties.Count; i++)
					{
						this.properties[i].Update();
						this.properties[i].SetLocalVelocity(this.transform.rotation, this.properties[i].velocity);
						if (this.properties[i].type == MANIPULATORPROPERTYTYPEC.Math)
						{
							this.properties[i].UpdateMathProperty(this.transform.position);
						}
					}
				}
			}
		}

		// Token: 0x06000886 RID: 2182 RVA: 0x000328AC File Offset: 0x00030AAC
		public virtual void SetTransform(Transform transform)
		{
			this.transform.SetFromTransform(transform);
		}

		// Token: 0x06000887 RID: 2183 RVA: 0x000328BC File Offset: 0x00030ABC
		public virtual void SetLocalTargetsPosition(Transform otherTransform)
		{
			this.property.SetLocalTargetsPosition(otherTransform);
			for (int i = 0; i < this.properties.Count; i++)
			{
				this.properties[i].SetLocalTargetsPosition(otherTransform);
			}
		}

		// Token: 0x06000888 RID: 2184 RVA: 0x00032904 File Offset: 0x00030B04
		public virtual ManipulatorObjectC Clone()
		{
			ManipulatorObjectC manipulatorObjectC = new ManipulatorObjectC();
			manipulatorObjectC.type = this.type;
			manipulatorObjectC.property = this.property.Clone();
			manipulatorObjectC.affects = this.affects;
			manipulatorObjectC.transform = this.transform.Clone();
			manipulatorObjectC.size = this.size;
			manipulatorObjectC.shape = this.shape;
			manipulatorObjectC.bounds = this.bounds;
			manipulatorObjectC.strength = this.strength;
			manipulatorObjectC.applyParticleLifetimeStrength = this.applyParticleLifetimeStrength;
			manipulatorObjectC.particleLifetimeStrength = new AnimationCurve(this.particleLifetimeStrength.keys);
			manipulatorObjectC.strengthSmoothing = this.strengthSmoothing;
			manipulatorObjectC.strengthDistanceEffect = this.strengthDistanceEffect;
			manipulatorObjectC.enabled = this.enabled;
			manipulatorObjectC.applyLifetimeFilter = this.applyLifetimeFilter;
			manipulatorObjectC.lifetimeFilterMinimum = this.lifetimeFilterMinimum;
			manipulatorObjectC.lifetimeFilterMaximum = this.lifetimeFilterMaximum;
			manipulatorObjectC.applyParticleFilter = this.applyParticleFilter;
			manipulatorObjectC.particleFilterMinimum = this.particleFilterMinimum;
			manipulatorObjectC.particleFilterMaximum = this.particleFilterMaximum;
			manipulatorObjectC.inverseBounds = this.inverseBounds;
			manipulatorObjectC.trackParticles = this.trackParticles;
			manipulatorObjectC.sendEventEnter = this.sendEventEnter;
			manipulatorObjectC.sendEventExit = this.sendEventExit;
			manipulatorObjectC.sendEventBirth = this.sendEventBirth;
			manipulatorObjectC.sendEventDeath = this.sendEventDeath;
			manipulatorObjectC.sendEventCollision = this.sendEventCollision;
			manipulatorObjectC.properties = new List<ManipulatorPropertyC>();
			manipulatorObjectC.axisConstraints = this.axisConstraints.Clone();
			for (int i = 0; i < this.properties.Count; i++)
			{
				manipulatorObjectC.properties.Add(this.properties[i].Clone());
			}
			return manipulatorObjectC;
		}

		// Token: 0x04000868 RID: 2152
		public MANIPULATORTYPEC type;

		// Token: 0x04000869 RID: 2153
		public ManipulatorPropertyC property = new ManipulatorPropertyC();

		// Token: 0x0400086A RID: 2154
		public List<ManipulatorPropertyC> properties = new List<ManipulatorPropertyC>();

		// Token: 0x0400086B RID: 2155
		public LayerMask affects;

		// Token: 0x0400086C RID: 2156
		public PlaygroundTransformC transform = new PlaygroundTransformC();

		// Token: 0x0400086D RID: 2157
		public MANIPULATORSHAPEC shape;

		// Token: 0x0400086E RID: 2158
		public float size;

		// Token: 0x0400086F RID: 2159
		public Bounds bounds;

		// Token: 0x04000870 RID: 2160
		public float strength;

		// Token: 0x04000871 RID: 2161
		public float strengthSmoothing = 1f;

		// Token: 0x04000872 RID: 2162
		public float strengthDistanceEffect = 1f;

		// Token: 0x04000873 RID: 2163
		public bool applyParticleLifetimeStrength;

		// Token: 0x04000874 RID: 2164
		public AnimationCurve particleLifetimeStrength = new AnimationCurve(new Keyframe[]
		{
			new Keyframe(0f, 1f),
			new Keyframe(1f, 1f)
		});

		// Token: 0x04000875 RID: 2165
		public bool enabled = true;

		// Token: 0x04000876 RID: 2166
		public bool inverseBounds;

		// Token: 0x04000877 RID: 2167
		public int manipulatorId;

		// Token: 0x04000878 RID: 2168
		public bool applyLifetimeFilter;

		// Token: 0x04000879 RID: 2169
		public float lifetimeFilterMinimum;

		// Token: 0x0400087A RID: 2170
		public float lifetimeFilterMaximum = 1f;

		// Token: 0x0400087B RID: 2171
		public bool applyParticleFilter;

		// Token: 0x0400087C RID: 2172
		public float particleFilterMinimum;

		// Token: 0x0400087D RID: 2173
		public float particleFilterMaximum = 1f;

		// Token: 0x0400087E RID: 2174
		public PlaygroundAxisConstraintsC axisConstraints = new PlaygroundAxisConstraintsC();

		// Token: 0x0400087F RID: 2175
		public bool unfolded;

		// Token: 0x04000880 RID: 2176
		public bool trackParticles;

		// Token: 0x04000881 RID: 2177
		public TrackingMethod trackingMethod;

		// Token: 0x04000882 RID: 2178
		public bool sendEventEnter = true;

		// Token: 0x04000883 RID: 2179
		public bool sendEventExit = true;

		// Token: 0x04000884 RID: 2180
		public bool sendEventBirth = true;

		// Token: 0x04000885 RID: 2181
		public bool sendEventDeath = true;

		// Token: 0x04000886 RID: 2182
		public bool sendEventCollision = true;

		// Token: 0x04000887 RID: 2183
		public bool sendEventsUnfolded;

		// Token: 0x04000888 RID: 2184
		[NonSerialized]
		public List<ManipulatorParticle> particles = new List<ManipulatorParticle>();

		// Token: 0x04000889 RID: 2185
		[NonSerialized]
		public List<ManipulatorParticle> nonAffectedParticles = new List<ManipulatorParticle>();

		// Token: 0x0400088A RID: 2186
		public PlaygroundEventParticle manipulatorEventParticle = new PlaygroundEventParticle();

		// Token: 0x0400088B RID: 2187
		[NonSerialized]
		protected bool initializedEventEnter;

		// Token: 0x0400088C RID: 2188
		[NonSerialized]
		protected bool initializedEventExit;

		// Token: 0x0400088D RID: 2189
		[NonSerialized]
		protected bool initializedEventBirth;

		// Token: 0x0400088E RID: 2190
		[NonSerialized]
		protected bool initializedEventDeath;

		// Token: 0x0400088F RID: 2191
		[NonSerialized]
		protected bool initializedEventCollision;
	}
}
